package com.example.visit

import android.graphics.Color
import androidx.databinding.DataBindingUtil
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.example.base.entity.VisitEntityItem
import com.example.visit.databinding.ItemVisitBinding


class VisitAdapter:BaseQuickAdapter<VisitEntityItem,BaseViewHolder>(R.layout.item_visit) {

    override fun onItemViewHolderCreated(viewHolder: BaseViewHolder, viewType: Int) {
        super.onItemViewHolderCreated(viewHolder, viewType)
        DataBindingUtil.bind<ItemVisitBinding>(viewHolder.itemView)
    }
    override fun convert(helper: BaseViewHolder, item: VisitEntityItem) {
        val binding = DataBindingUtil.getBinding<ItemVisitBinding>(helper.itemView)!!
        binding.bean=item

        binding.visitStatus.apply {
            when(item.visitStatus){
                "待审核"->{

                    setBackgroundResource(R.drawable.bg_red)
                }
                "已通过"->{
                    setBackgroundResource(R.drawable.bg_green)
                }
                "驳回"->{
                    setBackgroundResource(R.drawable.bg_yellow)
                }
            }
        }

        if(item.requestParking){
            binding.visitCar.setImageResource(R.drawable.ic_car_yes)
            binding.visitCarNo.setText("已申请车位")
            binding.visitCarNo.setTextColor(Color.BLUE)
        }else{
            binding.visitCar.setImageResource(R.drawable.ic_car_no)
            binding.visitCarNo.setText("未申请车位")
            binding.visitCarNo.setTextColor(Color.LTGRAY)
        }
    }
}